package com.dmooo.ymx.wmm;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.dmooo.ymx.CaiNiaoApplication;
import com.dmooo.ymx.config.Constants;

import java.util.ArrayList;

public class QQShareUtil {
    private static Bundle params;
    private static Tencent mTencent;
    static {
        mTencent= Tencent.createInstance("1107989076",CaiNiaoApplication.getAppContext());
    }
    public static void shareToQQ(String title,String summary,ArrayList<String> list,Activity activity, IUiListener listener) {
        params = new Bundle();
        ArrayList<String> temp=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            if(!list.get(i).startsWith("http")) {
                temp.add(Constants.APP_IP+ list.get(i).replace("\"", "").replace("\\", ""));
            }else{
                temp.add(list.get(i));
            }
        }
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, title);// 标题
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);// 摘要
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, temp.size()>0?temp.get(0):"");// 摘要
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,temp.size()>0?temp.get(0):"");
        params.putString(QQShare.SHARE_TO_QQ_EXT_INT, "其它附加功能");
        mTencent.shareToQQ(activity, params, listener);
    }
    /**
     * 分享本地图片到QQ
     *
     * @param imgUrl 图片url
     */
    public static void  shareImgToQQ(String imgUrl,Activity activity, IUiListener listener) {
        params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);// 设置分享类型为纯图片分享
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, imgUrl);// 需要分享的本地图片URL
        mTencent.shareToQQ(activity, params, listener);
    }
    /**
     * 分享本地图片到QQ空间
     *
     * @param imgUrl 图片url
     */
    public static void shareImgToQQZONE(String imgUrl,Activity activity, IUiListener listener) {
        params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);// 设置分享类型为纯图片分享
        params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, imgUrl);// 需要分享的本地图片URL
        params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
        mTencent.shareToQQ(activity, params, listener);
    }

    public static void shareToQZone(ArrayList<String> list,String title,String content,Activity activity, IUiListener listener) {
        params = new Bundle();
        ArrayList<String> temp=new ArrayList<>();
        for(int i=0;i<list.size();i++){
            if(!list.get(i).startsWith("http")) {
                temp.add(Constants.APP_IP+ list.get(i).replace("\"", "").replace("\\", ""));
            }else{
                temp.add(list.get(i));
            }
        }
        params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
        params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);// 标题
        params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
        params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, temp.size()>0?temp.get(0):"");// 摘要
        params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, temp);// 图片地址
        mTencent.shareToQzone(activity, params,listener);
    }
}
